/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.oszc.bbhmlibrary.database;

import ohos.app.Context;
import ohos.data.DatabaseHelper;
import ohos.data.rdb.RdbOpenCallback;
import ohos.data.rdb.RdbStore;
import ohos.data.rdb.StoreConfig;

public abstract class OpenSqliteHelper extends RdbOpenCallback {
    private final Context mContext;
    private final String mName;
    private final int mNewVersion;
    private DatabaseHelper mDatabaseHelper;
    public OpenSqliteHelper(Context mContext, String databaseName, int version) {
        this.mContext = mContext;
        this.mName = databaseName;
        this.mNewVersion = version;
        mDatabaseHelper = new DatabaseHelper(mContext);
    }

    public RdbStore getDatabase(){
        RdbStore rdbStore = mDatabaseHelper.getRdbStore(StoreConfig.newDefaultConfig(mName), mNewVersion, this);
        return rdbStore;
    }

    @Override
    public abstract void onCreate(RdbStore rdbStore);
    @Override
    public abstract void onUpgrade(RdbStore rdbStore,  int currentVersion,
                                   int targetVersion);
}
